﻿using Help;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Myproject
{
    /// <summary>
    /// LoginAjax 的摘要说明
    /// </summary>
    public class LoginAjax : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string userName = context.Request.Params["userName"];
            string passWord = context.Request.Params["passWord"];
            string logincode = context.Request.Params["logincode"];

            object obj = context.Session["validateCodeKey"];
            if (object.Equals(obj, null))
            {
                context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "验证码失效！"));
                return;
            }
            if (!context.Session["validateCodeKey"].ToString().ToLower().Equals(logincode.ToLower()))
            {
                context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "验证码错误"));
                return;
            }
            context.Response.Write(ReturnJsonHelp.OutHandlerJson(true, "登陆成功"));
            //using (UserBLL bll = new UserBLL())
            //{
            //    bool flag = bll.ExistsByNo(userName);
            //    if (flag)
            //    {
            //        UserModel user = bll.GetModelByNo(userName);

            //        //departmentModel department = new departmentBLL().GetModel(user.DepartmentID);
            //        //验证部门编号
            //        //if (department.DepartmentID == "00G" || department.DepartmentID == "006" || department.DepartmentID == "0IO")
            //        //{
            //        if (user.StopFlag)
            //        {
            //            context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "账号已被停用"));
            //        }
            //        else
            //        {
            //            //验证MAC地址
            //            //string MacAddress = new ArtsdonReport.cs.MacHelp().GetMac();

            //            //验证密码
            //            if (passWord.Equals(user.Password))
            //            {
            //                cookieHelp.ClearCookies();
            //                DepartmentModel dmodel = new DepartmentBLL().GetModel(user.DepartmentID);
            //                cookieHelp.SetCookies(user.UserID, user.No, user.UserName, user.DepartmentID, dmodel.Code, dmodel.DepartmentName);
            //                context.Response.Write(ReturnJsonHelp.OutHandlerJson(true, "登陆成功"));
            //            }
            //            else
            //            {
            //                context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "密码输入错误"));
            //            }
            //        }
            //        //}
            //        //else
            //        //{
            //        //    context.Response.Write(JsonHelp.OutHandlerJson(false, "无登陆权限！"));
            //        //}
            //    }
            //    else
            //    {
            //        context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "用户不存在"));
            //    }
            //}
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}